package com.demo.swagger.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("api")
@Api("swaggerDemoController相关的api")
public class SwaggerDemoController {


    private static final Logger logger = LoggerFactory.getLogger(SwaggerDemoController.class);


    @ApiOperation(value = "测试接口", notes = "测试测试")
    @ApiImplicitParam(name = "id", value = "测试", paramType = "path", required = true, dataType = "Integer")

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public JsonResult<PageModel<List<D>>> getStudent(@PathVariable int id) {
        D d1 = new D("aa",1);
        D d2 = new D("bb",2);
        D d3 = new D("c",3);
        List<D> list = new ArrayList<>();
        list.add(d1);
        list.add(d2);
        list.add(d3);
        PageModel p = new PageModel();
        p.setT(list);
        p.setSize(10);

        JsonResult result = new JsonResult();
        result.setCode("SUCCESS");
        result.setT(p);
        return result;
    }

    class D {
        private String name;
        private int age;

        public D(String name,int age) {
            this.name = name;
            this.age = age;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
